package com.nowar.frame.result;

import com.nowar.common.constant.CommonResultCode;
import com.nowar.common.result.response.ResponseCommonBase;
import com.nowar.exception.ServiceProxyException;

/**
 * @Author: 谢无殇。
 * @Date : 2023-01-31 21:38
 */
public class DefaultHandlerResult implements BaseHandlerResult {
    /**
     * 错误码
     */
    private int code;
    /**
     * 错误信息
     */
    private String message;

    @Override
    public void handlerResult(Object response) throws ServiceProxyException {
        if (response == null) {
            throw new ServiceProxyException(101, "请求结果为空");
        }
        if (response instanceof ResponseCommonBase) {
            ResponseCommonBase responseBase = (ResponseCommonBase) response;
            if (CommonResultCode.OK.getCode().equals(responseBase.getResultCode())) {
                System.out.println("结束或打印日志");
                return;
            }
            System.out.println("抛异常或打印日志");
        }
        throw new ServiceProxyException(102, "响应结果不对");
    }

    public DefaultHandlerResult(Object response) throws ServiceProxyException {
        handlerResult(response);
    }

    public DefaultHandlerResult() {
    }

    public DefaultHandlerResult(int code, String message) {
        this.code = code;
        this.message = message;
    }
}
